const util = require('/utils/util.js');
//app.js
App({
  capsule(e){
    var that = this;
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: res => {
        let statusBarHeight = res.statusBarHeight,
          navTop = menuButtonObject.top, //胶囊按钮与顶部的距离
          navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2; //导航高度
        var a = res.model;

        this.globalData.navHeight = navHeight;
        this.globalData.navTop = navTop;
        this.globalData.windowHeight = res.windowHeight;
        this.globalData.windowWidth = res.windowWidth;
        this.globalData.navWidth = menuButtonObject.width;
        this.globalData.left = menuButtonObject.left;
        this.globalData.right = menuButtonObject.right;
        this.globalData.navPosition = res.windowWidth - menuButtonObject.width - 2*(res.windowWidth - menuButtonObject.right);
        this.globalData.menuButtonRight = res.windowWidth - menuButtonObject.left - menuButtonObject.width;
        this.globalData.menuButtonwidth = res.windowWidth - (res.windowWidth - (menuButtonObject.width + (res.windowWidth - menuButtonObject.left - menuButtonObject.width)))
        
        if (this.userInfoReadyCallback) {
          this.userInfoReadyCallback(res)
        }
      },
      fail(err) {
        console.log(err);
      }
    })
  },
  onLaunch: function (options) {
    var that = this;
    var loginStatus = wx.getStorageSync("loginStatus") || [];
    var startTime = util.formatTime(new Date(), 'Y/M/D h:m:s');

    // 计算登录时间差 
    var total = (new Date(startTime).getTime() - new Date(loginStatus.token_expire).getTime()) / 1000;
    // 计算整数天数
    var day = parseInt(total / (24 * 60 * 60));
    // 取得算出天数后剩余的秒数
    var afterDay = total - day * 24 * 60 * 60;
    // 计算整数小时数
    var hour = parseInt(afterDay / (60 * 60));
    // 取得算出小时数后剩余的秒数
    var afterHour = total - day * 24 * 60 * 60 - hour * 60 * 60;
    // 计算整数分
    var min = parseInt(afterHour / 60);
    // 取得算出分后剩余的秒数
    var afterMin = total - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60;
    // 超时重新登录
    //|| !loginStatus.token
    // if (min > 0 || !loginStatus.token) {
    //   wx.removeStorage({
    //     key: "loginStatus"
    //   })
    //   wx.reLaunch({
    //     url: '/pages/login/login'
    //   })
    // } else {
    //   wx.reLaunch({
    //     url: '/pages/index/index'
    //   })
    // }
    wx.onNetworkStatusChange(function(res) {
      console.log(res.isConnected)
      console.log(res.networkType)
    })
    that.capsule()
  },

  onShow: function (options) {
    var that = this;
    that.capsule()
  },

  globalData: {
    navBg: '#09387B',
    navColor: '#fff'
  }
})